package com.zlm.user.emp.controller;

import com.zlm.common.base.BaseController;
import com.zlm.common.dto.JsonResultDto;
import com.zlm.common.entity.EmpUserEducationDO;
import com.zlm.user.emp.service.EmpUserEducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户教育经历controller
 * @Author: duyufu
 * @Date: 2019/5/14 16:48
 */
@RestController
@RequestMapping(value = "/empUserEducation")
public class EmpUserEducationController extends BaseController {

    @Autowired
    private EmpUserEducationService empUserEducationService;

    /**
     * 添加/修改教育经历
     * @param empUserEducationDO
     * @return
     */
    @PostMapping("/saveUserEducation")
    public JsonResultDto saveUserEducation(@RequestBody EmpUserEducationDO empUserEducationDO) {
        try {
            if (null == empUserEducationDO.getEid() ) {
                //新增教育经历
                empUserEducationService.insertUserEducation(empUserEducationDO);
            } else {
                //修改教育经历
                empUserEducationService.updateUserEducation(empUserEducationDO);
            }
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 删除教育经历
     * @param empId
     * @param eid
     * @return
     */
    @GetMapping("/deleteUserEducation")
    public JsonResultDto deleteUserEducation(Integer empId, Integer eid) {
        try {
            empUserEducationService.deleteUserEducation(empId,eid);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * 获取人才教育经历
     * @param empId
     * @return
     */
    @GetMapping("/queryUserEducation")
    public JsonResultDto queryUserEducation(Integer empId) {
        try {
            List<EmpUserEducationDO> educationList = empUserEducationService.queryUserEducation(empId);
            return success(educationList);
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

}
